import { constantRoutes, asyncRoutes } from '@/router/index'

const state = {
  routes: constantRoutes
}
const mutations = {
  set_Routes (state, payload) {
    state.routes = [...constantRoutes,...payload]
  }
}
const actions = {
  set_Routes (context, menus) {
    // 筛选出与员工的权限一样的路由，只渲染删选出来的路由
    const newRoutes =  asyncRoutes.filter(item => {
      // 这里得出来的值是true或false
        return menus.some(subitem => {
            // console.log(item);
            return item.children[0].name === subitem
        })
    })

    context.commit('set_Routes' , newRoutes)
    return newRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
